﻿using System.Web;
using Easy.BLL;
using Easy.Operation;

namespace Easy.Web.Service.Data
{
    /// <summary>
    /// GetListData 的摘要说明
    /// </summary>
    public class GetLinkListData : BaseHttpHandler
    {

        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            //string where = context.Request["where"];
            string order = context.Request["order"];
            string entityName = context.Request["entityname"];
            string filterData = context.Request["filter"];
            string type = context.Request["type"];
            string attribute = context.Request["attribute"];
            string attributevalue = context.Request["attributevalue"];

            string ViewName = context.Request["viewname"];
            if(string.IsNullOrWhiteSpace(ViewName))
            {
                ViewName = "DefaultView";
            }

            int pageNum=0;
            
            if (context.Request["pagenum"] != null)
            {
                pageNum = int.Parse(context.Request["pagenum"].ToString());

            }
            
            int pageSize=10;
            if (context.Request["pagesize"] != null)
            {
                pageSize = int.Parse(context.Request["pagesize"].ToString());

            }






            DataService service = new DataService(entityName, this.CurrentUserId);
            string returnValue = "";
            if (string.IsNullOrWhiteSpace(filterData))
            {
                //returnValue = service.RetrieveMultipleByView(order,"",ViewName, pageNum, pageSize);
                returnValue = service.RetrieveMultiple(ViewName, "", order, pageNum, pageSize);
            }
            else
            {
                //returnValue = service.RetrieveMultipleByView(order,filterData,ViewName, pageNum, pageSize);
                returnValue = service.RetrieveMultiple(ViewName, filterData, order, pageNum, pageSize);
            }


            context.Response.Write(returnValue);
        }

       
    }
}